//
//  StatusRetweetedCell.swift
//  01- 搭建框架
//
//  Created by apple on 15/10/21.
//  Copyright © 2015年 任伟. All rights reserved.
//

import UIKit

// 创建一个转发微博的 cell
class StatusRetweetedCell: StatusCell {
    
    override var viewModel: StatusViewModel? {
        didSet {
            // 转发微博文字
            retweetedLabel.text = viewModel?.retweetedText
        
            // TODO: -修改配图视图的顶部位置(自动布局有问题)
            pictureView.snp_updateConstraints { (make) -> Void in
               
                let offset = viewModel?.thumbnailUrls?.count > 0 ? StatusCellMargin : 0
                make.top.equalTo(retweetedLabel.snp_bottom).offset(offset)
                
            }
        }
    }

    /// MARK: -懒加载件
    // 懒加载图片
    private lazy var backButton: UIButton = {
        
        let button = UIButton()
        
        button.backgroundColor = UIColor(white: 1.00, alpha: 1.0)
        
        return button
    }()
    
    // 懒加载微博转发标签
    private lazy var retweetedLabel: UILabel = UILabel(title: "转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博",
        fontSize: 14,
        color: UIColor.darkGrayColor(),
        screenInset: StatusCellMargin)
}

/// MARK: -设置界面
extension StatusRetweetedCell {
    
    /// 设置界面
    override func setupUI() {
        super.setupUI()
        
        // 添加控件
        contentView.insertSubview(backButton, belowSubview: pictureView)
        contentView.insertSubview(retweetedLabel, belowSubview: pictureView)
        
        
        // 自动布局
        backButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.bottom.equalTo(bottomView.snp_top)
        }

        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(backButton.snp_top).offset(StatusCellMargin)
            make.left.equalTo(backButton.snp_left).offset(StatusCellMargin)
        }
    
    }

}
